/*
 * get_xplor.h
 *
 *  Created on: Apr 26, 2010
 *      Author: marchi
 */

#ifndef GET_XPLOR_H_
#define GET_XPLOR_H_
#include "typedefs.h"
#include "vec.h"

inline static int cell_angles(matrix box, real *a, real *b, real *g){
	real alpha,beta,gamma;

	if (norm2(box[YY])*norm2(box[ZZ])!=0)
		alpha = acos(cos_angle_no_table(box[YY],box[ZZ]));
	else
		alpha = 0.5*M_PI;
	if (norm2(box[XX])*norm2(box[ZZ])!=0)
		beta  = acos(cos_angle_no_table(box[XX],box[ZZ]));
	else
		beta  = 0.5*M_PI;
	if (norm2(box[XX])*norm2(box[YY])!=0)
		gamma = acos(cos_angle_no_table(box[XX],box[YY]));
	else
		gamma = 0.5*M_PI;
	*a=alpha;
	*b=beta;
	*g=gamma;

	return 0;
}
static inline int angles_cell(matrix box, rvec vec, rvec angles){
  for(int d;d<DIM;d++){
    box[XX][d]=0.0;
    box[YY][d]=0.0;
    box[ZZ][d]=0.0;
  }
  real ax=vec[XX];
  real alf=cos(angles[XX]);
  real bet=cos(angles[YY]);
  real qt=sin(angles[ZZ]);
  real gam=cos(angles[ZZ]);
  real bx=vec[YY]*gam;
  real by=vec[YY]*qt;
  real cx=vec[ZZ]*bet;
  real cy=vec[ZZ]*(alf-bet*gam)/qt;
  real cz=sqrt(vec[ZZ]*vec[ZZ]-cx*cx-cy*cy);
  box[XX][XX]=ax;
  box[YY][XX]=bx;
  box[ZZ][XX]=cx;
  box[YY][YY]=by;
  box[ZZ][YY]=cy;
  box[ZZ][ZZ]=cz;
  return 0;
}

extern int
get_xplor(real*** ,int, int, int, matrix, FILE *);

#endif /* GET_XPLOR_H_ */
